********************************************************************************
* This program runs all the necessary code to replicate the main results 
* in the paper
*
* Authors: Fowlie and Reguant
* August 2020
********************************************************************************



** BUILD DATA      *************************************************************

* cleaning raw data
do $buildpath/code/1_1_clean_ASM.do 
do $buildpath/code/1_2_clean_MECS.do 
do $buildpath/code/1_3_clean_QCEW.do 
do $buildpath/code/1_4_clean_SEDS.do 
do $buildpath/code/1_5_clean_CarbonIntensities.do 
do $buildpath/code/1_6_clean_deflators.do 
do $buildpath/code/1_7_clean_trade_data.do
do $buildpath/code/1_8_clean_IO_table.do 
* need to run in R
!Rscript "$buildpath/code/1_9_clean_exiobase.R" $dirpath

* merging energy variables data
do $buildpath/code/2_1_merge_misato_NAICS.do 
do $buildpath/code/2_2_merge_QCEW_SEDS_MECS.do 

* create key energy price and energy intensity data
do $buildpath/code/3_1_1_gen_energyprice_domestic.do 
do $buildpath/code/3_1_2_1_gen_energyprice_international_regionalpriceindex.do 
do $buildpath/code/3_1_2_2_gen_energyprice_international_allindustries_regionlevel.do 
do $buildpath/code/3_2_1_gen_energyintensities.do 
do $buildpath/code/3_2_2_gen_energyintensities_IO.do 
do $buildpath/code/3_3_gen_carbonintensities.do 
do $buildpath/code/3_4_gen_prices_intensities_comprehensive.do 
do $buildpath/code/3_5_gen_foreignprices_intensities_comprehensive.do 

* assemble all data for regressions
do $buildpath/code/4_create_main_regression_dataset.do


** ANALYZE DATA    *************************************************************

* regressions for transfer rate calibration
do $analyzepath/code/1_run_regressions.do

* prep simulations
do $analyzepath/code/2_1_gen_simulation_data.do
do $analyzepath/code/2_2_gen_transferrate_data.do 

* simulations
do $analyzepath/code/3_run_simulations.do


** PRODUCE OUTPUTS *************************************************************

* produce main tables
do $producepath/code/1_create_tables.do

* produce main figures
do $producepath/code/2_create_figures.do
